.PHONY: all test clean deps tags 

CXX=g++ -std=c++11
CXXFLAGS += -g -Wall -Wno-reorder -fsanitize=address
LDFLAGS += -pthread

DEPS_INCLUDE_PATH=-I deps/tinyxml -I /usr/include/mysql -I deps/log4cxx/include -I deps/fastdfs/include/client -I deps/fastdfs/include/fastdfs -I deps/fastdfs/include/fastcommon
DEPS_LIB_PATH=-L /usr/lib64/mysql deps/tinyxml/libtinyxml.a deps/log4cxx/lib/liblog4cxx.a deps/log4cxx/lib/libapr-1.a deps/log4cxx/lib/libaprutil-1.a deps/log4cxx/lib/libexpat.a  -L./deps/fastdfs/lib
SRC_INCLUDE_PATH=-I src
OUTPUT_INCLUDE_PATH=-I output/include
OUTPUT_LIB_PATH=output/lib/libsimpleserver.a

objects := $(patsubst %.cpp,%.o,$(wildcard src/*.cpp))

LFLAGS= -lmysqlclient -lfastcommon -lfdfsclient

all: prepare deps libsimpleserver.a
	cp src/*.h output/include/
	mv libsimpleserver.a output/lib/

prepare: 
	mkdir -p output/include output/lib output/bin

tags:
	ctags -R /usr/include src deps

deps:
	make -C deps/tinyxml

libsimpleserver.a: $(objects)
	ar -rcs libsimpleserver.a src/*.o

test: voice_server_test

%.o: %.cpp
	$(CXX) -c $(CXXFLAGS) $(DEPS_INCLUDE_PATH) $(SRC_INCLUDE_PATH) $< -o $@

voice_server_test: voice/voice_server_test.cpp
	$(CXX) $(LFLAGS) $(CXXFLAGS) $(LDFLAGS) $(DEPS_INCLUDE_PATH) $(OUTPUT_INCLUDE_PATH) $< $(OUTPUT_LIB_PATH) $(DEPS_LIB_PATH) -o output/bin/$@

clean:
	rm -rf src/*.o
	rm -rf output/*
	rm -rf log/*

